import { defineStore } from 'pinia'
import { ElMessage } from 'element-plus'
import $axios from '../tools/axios'


const basepath = '/user'
export const useRegisterStore = defineStore('register', {
  state: () => {
    return {
      formData: {
        userid:'',
        username: '',
        password: '',
        idtype: '1',
        name: '',
        id: '',
        favortype: '1',
        email: '',
        mobiletype: '1',
        mobile: '',
        amount: ''
      },
      code: '',
    }
  },
  actions: {

    async register() {
        const path = basepath + '/register'
        const { data: res } = await $axios.put(path, this.formData)
  
        if (res.code === 200) {
            ElMessage({
                message: '恭喜您，注册成功！',
                type: 'success',
              })
              console.log('新增记录的主键 = '+res.data);
     
       
        }
        else {
            ElMessage.error('注册失败！')
        }
      },

      async sendPhoneMessage() {
        const path = basepath + '/sendPhoneMessage'
        const { data: res } = await $axios.put(path, this.formData)
  
        if (res.code === 200) {
           
            console.log(res.data);
            this.code = res.data;
       
        }
        else {
            ElMessage.error('验证码发送失败！')
            console.log(res);
        }
      },

      
  }
})
